home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 12 - 1996 / 12.12 Dec 96 / Async I⁄O Code / Sources / OSGlue.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-06  |  2.0 KB  |  94 lines  |  [TEXT/R*ch]

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stat.h>
  4. #include <unistd.h>
  5.  
  6. #include "LabMaker.h"
  7.  
  8. #define kPathChar ':'
  9.  
  10. static void MakeFullPath(char* partialPath, char* fullPath);
  11. extern CurrentState    gCurrState;
  12.  
  13. void Error(char* message, char *buffer, short index, char* fileName)
  14. {
  15. #pragma unused(index, buffer)
  16.     printf("ERROR: %s\n  file %s;\n  %s\n", message, fileName, gCurrState.buffer);
  17. #if 0
  18.     puts("  ");
  19.     while (index-- > 0)
  20.         putchar(' ');
  21.     puts("^\n");
  22. #endif
  23. }
  24.  
  25.  
  26. void Warning(char* message, char *buffer, short index, char* fileName)
  27. {
  28. #pragma unused(index, buffer)
  29.     printf("WARNING: %s\n;  file %s;\n  %s\n", message, fileName, gCurrState.buffer);
  30. #if 0
  31.     puts("  ");
  32.     while (index-- > 0)
  33.         putchar(' ');
  34.     puts("^\n");
  35. #endif
  36. }
  37.  
  38.  
  39. int GetOrMakeDirectory(char *path, short isFullPath)
  40. // Returns an error code, or 0 if successful
  41. {
  42.     char    fullPath[kFullPathLength];
  43.  
  44.     if (!isFullPath)
  45.         MakeFullPath(path, fullPath);
  46.     else
  47.         strcpy(fullPath, path);
  48.  
  49.     return mkdir(fullPath, 0);
  50. }
  51.  
  52. // Locate or create the specified file and open it
  53. FILE* GetOrMakeFile(char* fileName, char *path, short isFullPath)
  54. {
  55.     char    fullPath[kFullPathLength];
  56.     short    length;
  57.     FILE*    result;
  58.     
  59.     if (!isFullPath)
  60.         MakeFullPath(path, fullPath);
  61.     else
  62.         strcpy(fullPath, path);
  63.  
  64.     // Make sure there's one final path seperator between the path
  65.     // and the file name
  66.     length = strlen(fullPath);
  67.     if (*fileName != kPathChar) {
  68.         fullPath[length++] = kPathChar;
  69.         fullPath[length++] = '\0';
  70.     }
  71.     
  72.     // Append the file name to the path name and open the file
  73.     strcat(fullPath, fileName);
  74.     result = fopen(fullPath, "w");
  75.     return result;
  76. }
  77.  
  78. // Locate or create the specified file
  79. int CopyFile(char* sourceFileName, char *sourcePath, char* copyPath, short isFullPath)
  80. {
  81. #pragma unused (sourceFileName, sourcePath, copyPath, isFullPath)
  82.     DebugStr("\pCopyFile must be implemented");
  83.     // <<< Write
  84.     return -1;
  85. }
  86.  
  87. // --- Utility functions
  88. void MakeFullPath(char* partialPath, char* fullPath)
  89. {
  90.     getcwd(fullPath, kFullPathLength);
  91.     // We have the working directory, so now append our partial path
  92.     strcat(fullPath, partialPath);
  93. }
  94.